<?php
   namespace app\admin\controller;
   class Stand extends \think\Controller{
   	public $mec;
  	function __construct(){
  		parent::__construct();
      $this->mec=new \app\admin\controller\Memcache();
  	}
  	function stand_mem(){
	        $list=\think\Db::name('stand')->select();
	        foreach($list as $k=>$v){
	        	$list[$k]['stand_list']=explode(',',$v['stand_list']);
	        }
            $this->mec->mem->set('stand',$list);
}

      function index(){
      	 if(!$stand=$this->mec->mem->get('stand')){
      	 	 $this->stand_mem();
      	 }
      	 $this->assign('stand',$this->mec->mem->get('stand'));
         return $this->fetch('index/stand_data');
      }

      function stand_add(){
      	 if(input('get.id')){
      	 	 $row=\think\Db::name('stand')->find(input('get.id'));
	        	$row['stand_list']=explode(',',$row['stand_list']);
	        $this->assign('row',$row);
      	 }
         return $this->fetch('index/stand');
      }

      function stand_save(){
      	$post=input('post.');
      	$post['stand_list']=join(',',$post['stand_list']);
      	$res=\think\Db::name('stand')->insert($post);
      	if($res){
      		$this->stand_mem();
      		echo json_encode(['status'=>'ok']);
      	}else{
      		echo json_encode(['status'=>'fail']);
      	}
      }

      function stand_edit(){
      	 $post=input('post.');
      	$post['stand_list']=join(',',$post['stand_list']);
      	$res=\think\Db::name('stand')->where('id',input('get.id'))->update($post);
      	if($res){
      		$this->stand_mem();
      		echo json_encode(['status'=>'ok']);
      	}else{
      		echo json_encode(['status'=>'fail']);
      	}
      }


      function stand_delt(){
      	$res=\think\Db::name('stand')->delete(input('post.id'));
      	if($res){
      		$this->stand_mem();
      		echo json_encode(['status'=>'ok']);
      	}else{
      		echo json_encode(['status'=>'fail']);
      	}
      }
   }
?>